package com.jxau.mall.demo.service.Impl;

import com.jxau.mall.demo.service.IGrpcClientService;
import com.jxau.mall.proto.Cart;
import com.jxau.mall.proto.RequestParam;
import com.jxau.mall.proto.ResponseResult;
import com.jxau.mall.proto.RpcSimpleGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: shop
 * @description: 接口实现类
 * @author: guojiani
 * @create: 2025-04-27 15:46
 **/
@Service
public class GrpcClientServiceImpl implements IGrpcClientService {
    @GrpcClient("sku-grpc")
    private RpcSimpleGrpc.RpcSimpleBlockingStub simpleBlockingStub ;
    @Override
    public void save(List<Cart> carts) throws Exception {
        // 构建请求参数
        RequestParam requestParam = RequestParam.newBuilder().addAllCarts(carts).build();
        // 发起RPC调用
        ResponseResult result = simpleBlockingStub.dcount(requestParam);
        // 处理返回结果
        if (result.getCode() == 1000){
            throw new Exception(result.getMessage());
        }
    }
}
